package com.runjian.rundo.iot.agent.iec104.parser.frame.control.system;

import java.util.List;

import cn.hutool.core.collection.ListUtil;
import com.runjian.rundo.iot.agent.iec104.consts.Action;
import com.runjian.rundo.iot.agent.iec104.consts.Cot;
import com.runjian.rundo.iot.agent.iec104.consts.QOI;
import com.runjian.rundo.iot.agent.iec104.consts.Ti;
import com.runjian.rundo.iot.agent.iec104.parser.frame.ASDUFrame;
import com.runjian.rundo.iot.agent.iec104.parser.frame.InfoElement;

import cn.hutool.core.util.ByteUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * C_IC_NA_1(100, "总召唤命令")
 *
 * @author CaoQingHua
 */
@Getter
@Setter
public class C_IC_NA_1 extends ASDUFrame {

    @Override
    public void init() {
        // 激活确认
        this.setCot(Cot.ACT);
        // 类型
        this.setTi(Ti.C_IC_NA_1);
        // 限定词
        this.setQos(QOI.ACT.getCode());
        // 初始化一个信息元素
        InfoElement infoElement = InfoElement.<Void>builder().address(0).build();
        this.addInfoElement(infoElement);
    }

    @Override
    public void analysisInfo(byte[] msg) {
        this.addInfoElement(InfoElement.builder().address(ByteUtil.bytesToInt(new byte[] {msg[12], msg[13], msg[14], 0x00}))
            .qds((short)(msg[15] & 0xff)).build());
    }

    @Override
    public List<Action> action() {
        if (this.getCot() == Cot.ACTTERM) {
            // 发送S侦
            return ListUtil.of(Action.SEND_S_DETECT);
        }else{
            return null;
        }
    }

}
